package cn.cj.erp.common.vo.login;

import cn.cj.erp.common.utils.encrypt.AesUtil;
import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

/**
 * 修改密码dto
 * @author chenjian
 */
@Data
public class PasswordChangeVo {
    /** 用户ID */
    @JsonSerialize(using = ToStringSerializer.class)
    @NotNull(message = "用户ID不能为空")
    private Long userId;

    /** 新密码 */
    @NotBlank(message = "新密码不能为空")
    private String newPassword;

    /** 密码 */
    @NotBlank(message = "原密码不能为空")
    private String password;

    /** uuid */
    @NotBlank(message = "uuid不能为空")
    private String uuid;

    public void decrypt() {
        this.newPassword = AesUtil.decrypt(StrUtil.replace(this.newPassword, " ", "+"),
                this.uuid.substring(16));
        this.password = AesUtil.decrypt(StrUtil.replace(this.password, " ", "+"),
                this.uuid.substring(16));
    }
}
